<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>运动健康</title>
    <script src="./index.js"></script>
    <script src="./jquery.js"></script>
    <link rel="stylesheet" href="./indx.css">
</head>

<body>
    <div>
        <div class="head">
            <span>医院排队叫号候诊</span>
            <div class="box_righ">
                <div class="left">
                    <div class="top" id="date"></div>
                    <div class="bt">
                        <div class="l" id="week">
                        </div>
                        <div class="r" id="time">
                        </div>
                    </div>
                </div>
                <img src="./img.png" class="right" alt="">
            </div>
        </div>
        <div class="btm">
            <div class="head_t">
                <div>工作室名称</div>
                <div>当前就诊</div>
                <div>等待呼叫</div>
            </div>
            <div class="body" id="box">

            </div>
        </div>
    </div>
</body>
</script>
<script>
    var timer;
    //重呼
    function callSound() {
        $.ajax({
            type: "get",
            url: "https://health9.westts.cn/expert/pager/pager/call",
            dataType: "json",
            success: res => {
                if (res.result != '') {
                    btnRst_Click(res.result)
                } else {
                    setTimeout(() => {
                        callSound()
                    }, 2000)
                }
            },
            error: err => {
            }
        })
    }
    $(function () {// 初始化内容
        getList()
        getCurrentTime()
        callSound()
    });
   setInterval(() => {
        getList()
        getCurrentTime()
    }, 1000)
    //获取列表
    function getList() {
        $.ajax({
            type: "get",
            url: "http://121.31.122.116:8899/expert/pager/pager/screen/1593586867838713858",
            dataType: "json",
            success: res => {
                $('#box').children().remove()
                res.result.forEach(item => {
                    if (item.current.length > 0) {
                        item.current = item.current.toString()
                    }
                    if (item.waits.length > 0) {
                        item.waits = item.waits.toString()
                    }
                    let contenet = `
                    <ul>
                    <li>${item.name}</li>
                    <li class="name">${item.current}</li>
                    <li>${item.waits}</li>
                </ul>
                    `
                    $('#box').append(contenet)
                });

            },
            error: err => {
                clearInterval(timer)
            }
        })
    }
    //获取当前时间
    function getCurrentTime() {
        var date = new Date();
        let year = date.getFullYear(); //获取完整的年份(4位)
        let mouth = date.getMonth(); //获取当前月份(0-11,0代表1月)
        let day = date.getDate(); //获取当前日(1-31)
        let week = date.getDay(); //获取当前星期X(0-6,0代表星期天)
        date.toLocaleDateString(); //获取当前日期
        var mytime = date.toLocaleTimeString(); //获取当前时间
        $('#date').html(`${year}-${mouth}-${day}`)
        $('#week').html(`星期${week}`)
        $('#time').html(mytime)
    }
    //语音播放
    function btnRst_Click(e) {
        window.utterances = [];
        const synth = window.speechSynthesis;
        utterances.push(synth);
        const msg = new SpeechSynthesisUtterance()
        msg.text = e;//文字内容
        msg.lang = "zh-CN";//使用的语言:中文
        synth.cancel();
        msg.volume = 1;
        //声音音量:0-1
        msg.rate = 0.8;
        //语速:0-10
        msg.pitch = 0.8;
        //音高:0-1
        synth.speak(msg);
        //播放
        msg.onend = () => {
            console.log('播放完毕', e);
            setTimeout(() => {
                callSound()
            }, 2000)
        }
    }

</script>

</html>